package com.youfang.sixthmedia.widget;

import java.util.List;

import android.content.Context;
import android.graphics.drawable.BitmapDrawable;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageSwitcher;
import android.widget.ImageView;
import android.widget.ViewSwitcher.ViewFactory;

import com.youfang.sixthmedia.message.model.Advertisment;

/**
 * 广告切换的逻辑
 * 
 * TODO:加入轮播机制
 * 
 * @author teddy
 * 
 */
public class AdImageSwitcher extends ImageSwitcher implements ViewFactory {

	public AdImageSwitcher(Context context, AttributeSet attrs) {
		super(context, attrs);
		this.setFactory(this);
	}

	public void setAds(List<Advertisment> ads) {
		this.setImageDrawable(new BitmapDrawable(ads.get(0).getAdImage()));

	}

	@Override
	public View makeView() {
		ImageView iv = new ImageView(this.getContext());
		iv.setBackgroundColor(0xFF000000);
		iv.setScaleType(ImageView.ScaleType.FIT_XY);
		iv.setLayoutParams(new ImageSwitcher.LayoutParams(
				LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
		return iv;
	}

}
